<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Http\Models\PostCid;


class PostCidController extends Controller {


    public function index(Request $request)
    {
        $cids = PostCid::all();

        return view("admin.postCid.index",['cids'=>$cids,'active'=>'post']);
    }

    public function create(Request $request)
    {
        return view('admin.postCid.create',['active'=>'post']);
    }

    public function store(Request $request){
        $postCid = new PostCid;
        $postCid -> title = $request->input('title');
        $postCid -> save();

        return redirect('/administrator/postCid');
    }

    public function edit($id){

        $postCid = PostCid::find($id);

        return view('admin.postCid.edit',['postCid'=>$postCid,'active'=>'post']);
    }


    public function update(Request $request,$id)
    {
        $postCid = PostCid::find($id);

        $postCid ->title = $request -> input('title');

        $postCid->save();

        return redirect('/administrator/postCid');
    }

    public function delete($id)
    {
        $res = PostCid::destroy($id);
        if($res) return view('success',['url'=>'/administrator/post']);

        return view('failure',['url'=>'/administrator/post']);
    }




}


